﻿var timeOutEvent=0 ;
var rot = 0 ;
var timer = '';
var rot2 = 0;
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

$(function(){
	$("#game_area").on({
		touchstart: function(e){
			timeOutEvent = setInterval(function(){
				$(".game1").css({'-webkit-transform':'rotate('+(rot2+rot)+'deg)','transform':'rotate('+(rot2+rot)+'deg)','-webkit-transition':'all ease-in-out'})
				$(".game3").css({'-webkit-transform':'rotate(-'+(rot2+rot)+'deg)','transform':'rotate(-'+(rot2+rot)+'deg)','-webkit-transition':'all ease-in-out'})
				$(".game4").addClass(' line_move');
				
				if ( rot>500 ){
					rot = rot+5.55;
					if( rot>=1500&&rot<1505 ){
						if( !prop_is_help ){
							func_help(pub_id);
						}else{
							$('#toast').toast('你已点亮过了哦~');
						}
					}
				}else if ( rot>90 ){
					rot = rot+(rot/90);
				}else{
					rot +=0.5;
				}
				console.log(rot)
				
			},5);
			
		 	e.preventDefault();
		},
		touchend: function(){
			clearInterval(timeOutEvent);
			rotateEnd();
		}
	})
	
});

function progress(perc){
	setTimeout(function(){
		 if ( perc <=50 ) {
			$(".cricle_progress_bar_right_c").css('transform','rotate('+perc*3.6+'deg)');
		}else{
			$(".cricle_progress_bar_right_c").css('transform','rotate(180deg)');
			setTimeout(function(){
				$(".cricle_progress_bar_left_c").css('transform','rotate('+((perc-50)*3.6)+'deg)');
			},1000)
		}
		$(".cricle_progress_bar,.cricle_progress_bar_right_c,.cricle_progress_bar_left_c").css('transition','all linear 1s');
	},100)
}

function rotateEnd(){
	//clearInterval(timeOutEvent);
		
	if ( rot>5000 ){
		rot2 = rot2+rot+180;
	}else if ( rot>1500 ){
		rot2 = rot2+rot+70;
	}else if ( rot>500 ){
		rot2 = rot2+rot+50;
	}else if ( rot>90 ){
		rot2 = rot2+rot+10;
	}else{
		rot2 = rot2+rot+5;
	}
	$(".game1").css({'-webkit-transform':'rotate('+rot2+'deg)','transform':'rotate('+rot2+'deg)','-webkit-transition':'all 1s '})
	$(".game3").css({'-webkit-transform':'rotate(-'+rot2+'deg)','transform':'rotate(-'+rot2+'deg)','-webkit-transition':'all 1s'})
	$(".game4").removeClass('line_move').css('-webkit-transition','all 1s ease');
	
	rot2 = rot2>360 ? rot2-360 : rot2;
	rot = 0;
//	rot2 = 0;
	return false; 
}

function setItem(){
	var dotLeft = $(".deng_area").width()/2;
	var dotTop = $(".deng_area").height()/2;
	var stard = 0;
	var radius = dotLeft;
	var avd = 360/$(".deng_item").length;
	//每一个BOX对应的弧度;
	var ahd = avd*Math.PI/180;
	
	
	var box_left = $(".deng_item").width()/2;

	//设置圆的中心点的位置
	$(".deng_item").each(function(index, element){
		var delay = Math.random()*0.85;
        $(this).css({
        	"left":Math.sin((ahd*index))*radius+dotLeft-box_left,
        	"bottom":Math.cos((ahd*index))*radius+dotTop-box_left,
        	'transition': 'all 1s ease '+delay+'s',
    	    '-webkit-animation':' up_d 2s linear '+(2+delay)+'s infinite',
    		'animation': 'up_d 2s linear '+(2+delay)+'s infinite'
        });
    });
    setTimeout(function(){
    	$(".deng_area").css('z-index','1')
    },2000)
}
function func_wx_pic_name (str,num) {
    var start =  0;
    var lenght = str.length-1;
    var string = str.substr(start,lenght);
    string = string+''+num+'';
    return string;  
}
function img_url(url){
    var path;
    if(url.indexOf("http")!=-1){
        path = url;
    }
    else
    {
        path = pub_upload_root_url + url;
    }
    return path;
}

//普通alert
function func_alert(text){
    var html = '<div class="weui_dialog_alert" id="n_alert" style="display: none;"><div class="weui_mask"></div><div class="weui_dialog"><div class="weui_dialog_hd"><strong class="weui_dialog_title">提示</strong></div><div class="weui_dialog_bd"></div><div class="weui_dialog_ft"><a href="javascript:;" class="weui_btn_dialog primary">确定</a></div></div></div>';
    $('body').append(html);
    var tk = $('#n_alert');

    tk.find('.weui_dialog_bd').html(text);
    tk.find(".weui_btn_dialog").click(function() {
        tk.hide();
    });
    tk.show();
}

$(function(){
	$('.rule').click(function(){
		$('.rule_mask').show();
		$('.rule_box').removeClass('out').addClass('in');
	})
	$('.rule_mask .rule_close').click(function(){
		$('.rule_box').removeClass('in').addClass('out');
		setTimeout(function(){
			$('.rule_mask').hide();
		},800)
	})
})

;(function (doc, win) {
  var docEl = doc.documentElement,
    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function () {
      var clientWidth = docEl.clientWidth;
      if (!clientWidth) return;
      docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
    };

  if (!doc.addEventListener) return;
  win.addEventListener(resizeEvt, recalc, false);
  doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

;(function($) {
		var style="<style>#toast{position: fixed;top: 0;left: 0;right: 0;bottom: 0;display: flex;display: -webkit-flex;justify-content:center;align-items: center;z-index:66;}.toast_cont{padding:10px;border-radius: 5px;max-width:150px;color: white;text-align: center;font-size: 14px;background: rgba(0,0,0,0.9);}</style>";
		var html = '<div id="toast" style="display:none;"><div class="toast_cont"></div></div>';
		$('body').append(html);
		$('head').append(style);
		$.fn.toast = function(content) {
			var t = $(this);
			t.find(".toast_cont").html(content);
			t.fadeIn('slow');
			
			setTimeout(function(){
				t.fadeOut('slow');
			},1000)
		}		
	})($);